package gs.android.calcfeud;

import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;

public class GameController implements OnTouchListener {
	private GamePersistor persistor;
	
	public GameController(GamePersistor persistor) {
		this.persistor = persistor;
	}

	@Override
	public boolean onTouch(View v, MotionEvent event) {
		if (event.getAction() == MotionEvent.ACTION_DOWN) {
			float x = event.getX();
			float y = event.getY();
			
			Button roll = persistor.getModel().getButton();
			Dice dice = persistor.getModel().getDice();
			if (roll.isPressed(x, y)) {
				if (!dice.isRolling())
					dice.roll();
			}
		}
		return false;
	}
    
    public boolean onKeyDown(int keyCode, KeyEvent event) {
    	if (keyCode == KeyEvent.KEYCODE_BACK) {
    		//TODO exit game screen
    		persistor.finish();
    	}
    	return false;
    }
	
	public void onPause() {
		
	}
	
	public void onResume() {
		
	}
}